//
//  MyBookingViewController.m
//  GuoBang
//
//  Created by fengshuai on 16/4/29.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "MyBookingViewController.h"
#import "WeiZhiFuViewController.h"
#import "YiZhiFuViewController.h"
#import "DingPingJiaViewController.h"

@interface MyBookingViewController ()<UIScrollViewDelegate,helpPushDelegate>
{
    UIView  *contview;
    WeiZhiFuViewController *weizhiVC;
    YiZhiFuViewController *yizhifuVC;
}
@end

@implementation MyBookingViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupNVA];
    [self setupUI];
    [self setupData];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)setupNVA
{
    self.title=@"我的订单";
    //设置返回按键
    //返回按键颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //返回按键图标
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}

- (void)leftAction:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupData
{
    
    
}

- (void)setupUI
{
    self.view.backgroundColor = RGBCOLOR(245, 245, 245);
    self.menuItem = @[@"未支付", @"已支付"];
    self.control = [[UISegmentedControl alloc] initWithItems:self.menuItem];
    self.control.frame = CGRectMake(-2, 64, WIDTH+4, HEIGHT / 12);
    self.control.backgroundColor = RGBCOLOR(244, 244, 249);
    self.control.tintColor =[UIColor clearColor];
    self.control.selectedSegmentIndex = 0;
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                             NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:109/255.0 blue:109/255.0 alpha:1.0]};
    [self.control setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    //设置文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                               NSForegroundColorAttributeName: [UIColor blackColor]};
    [self.control setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    [self.control addTarget:self action:@selector(selectedSegment:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.control];
    
    
    contview = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.control.frame), (self.menuItem.count * WIDTH), HEIGHT-CGRectGetMaxY(self.control.frame))];
    yizhifuVC = [YiZhiFuViewController new];
    yizhifuVC.delegate = self;
    yizhifuVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, CGRectGetHeight(contview.frame));
    weizhiVC = [WeiZhiFuViewController new];
    weizhiVC.view.frame = CGRectMake(0, 0, WIDTH, CGRectGetHeight(contview.frame));
    [contview addSubview:weizhiVC.view];
    [contview addSubview:yizhifuVC.view];
    [self.view addSubview:contview];
    
    
}


-(UISegmentedControl *)control
{
    if (!_control) {
        self.control = [[UISegmentedControl alloc] initWithItems:_menuItem];
        self.control.backgroundColor = RGBCOLOR(244, 244, 249);
        self.control.tintColor =[UIColor clearColor];
        self.control.selectedSegmentIndex = 0;
        [self.control addTarget:self action:@selector(selectedSegment:) forControlEvents:UIControlEventValueChanged];
    }
    return _control;
}


// 分段控件选择的方法
- (void)selectedSegment:(UISegmentedControl *)sender
{
    NSInteger i = sender.selectedSegmentIndex;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2]; //动画时长
    contview.frame = CGRectMake(-i*WIDTH, CGRectGetMaxY(self.control.frame), 2*WIDTH, HEIGHT-CGRectGetMaxY(self.control.frame));
    [UIView commitAnimations];
    [contview setNeedsDisplay];
    switch (i) {
        case 0:
        {
            NSLog(@"%ld", (long)i);
        }
            break;
        case 1:
        {
            NSLog(@"%ld", (long)i);
        }
            break;
        default:
            break;
    }
    
}


- (void)helpPush
{
    DingPingJiaViewController *pingJiaVC = [DingPingJiaViewController new];
    [self.navigationController pushViewController:pingJiaVC animated:YES];
    
}











@end
